//
//  LGMedicineRecordCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/10/9.
//

#import "LGMedicineRecordCell2.h"

@interface LGMedicineRecordCell2()

/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *typeLabel;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *remarkLabel;
/**   */
@property (nonatomic , strong)UILabel *tipLabel;


@end

@implementation LGMedicineRecordCell2

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setType:(NSString *)type{
    _type = type;
    if([type isEqualToString:@"top"]){
        //第一个
        self.baseView.layer.cornerRadius = 15;
        [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(viewPix(16));
        }];
        [self.tipLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView).offset(-viewPix(6));
        }];
        [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(viewPix(4));
            make.bottom.equalTo(self.contentView).offset(viewPix(16));
        }];
    }else if ([type isEqualToString:@"middle"]){
        //中间
        self.baseView.layer.cornerRadius = 0;
        [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(viewPix(6));
            make.bottom.equalTo(self.contentView).offset(-viewPix(10));
        }];
        [self.tipLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView).offset(-viewPix(6));
        }];
        [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(-viewPix(16));
            make.bottom.equalTo(self.contentView).offset(viewPix(16));
        }];
    }else if ([type isEqualToString:@"bottom"]){
        //底部
        self.baseView.layer.cornerRadius = 15;
        [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(viewPix(6));
        }];
        [self.tipLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView).offset(-viewPix(16));
        }];
        [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(-viewPix(16));
            make.bottom.equalTo(self.contentView).offset(-viewPix(4));
        }];
    }else{
        self.baseView.layer.cornerRadius = 15;
        [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(viewPix(16));
        }];
        [self.tipLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView).offset(-viewPix(16));
        }];
        [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(viewPix(4));
            make.bottom.equalTo(self.contentView).offset(-viewPix(4));
        }];
    }
}



-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    BOOL isStop = NO;
    NSString *realityDose = LGNSString(dataDic[@"reality_dose"]);
    self.tipLabel.textColor = [UIColor colorWithString:@"#999999"];
    if([realityDose isEqualToString:@"-1"]){
        //完全按医嘱
        self.tipLabel.text = @"完全按医嘱";
    }else if ([realityDose isEqualToString:@"-2"]){
        //未吃
        isStop = YES;
        self.tipLabel.text = [NSString stringWithFormat:@"停药:%@",dataDic[@"memo"]];
        self.tipLabel.textColor = [UIColor colorWithString:@"#EB5757"];
    }else if (realityDose.length == 0){
        //没选择
        self.tipLabel.text = @"";
    }else{
        //其他用药情况
        self.tipLabel.text = [NSString stringWithFormat:@"%@%@ ,  %@",dataDic[@"reality_dose"],dataDic[@"dose_unit"],dataDic[@"reality_take_frequency"]];
    }
    
    if([dataDic[@"advice_type"] isEqualToString:@"in"]){
        self.typeLabel.text = @"医嘱";
        self.typeLabel.textColor = [UIColor colorWithString:@"#4C87FD"];
        self.typeLabel.backgroundColor = [UIColor colorWithString:@"#EAF4FF"];
        [self.typeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(viewPix(30)));
        }];

    }else{
        self.typeLabel.text = @"医嘱外";
        self.typeLabel.textColor = [UIColor colorWithString:@"#31A952"];
        self.typeLabel.backgroundColor = [UIColor colorWithString:@"#ECFBED"];
        self.tipLabel.text = @"";
        [self.typeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(viewPix(35)));
        }];
    }
    NSString *content = [NSString stringWithFormat:@"%@(%@)，%@%@，%@，%@",dataDic[@"title"],dataDic[@"spec"],dataDic[@"advice_dose"],dataDic[@"dose_unit"],dataDic[@"take_method"],dataDic[@"advice_take_frequency"]];
    NSMutableAttributedString *attrbutString = [[NSMutableAttributedString alloc]initWithString:content];
    if(isStop == YES){
        [attrbutString addAttributes:@{NSStrikethroughStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle]} range:NSMakeRange(0, content.length)];
    }
    self.titleLabel.attributedText = attrbutString;
    
    NSString *remark = @"";
    self.remarkLabel.text = (remark.length>0)?[NSString stringWithFormat:@"备注：%@",remark]:@"";
    CGFloat remarkTop = (remark.length>0)?viewPix(8):0;
    CGFloat stopTop = (self.tipLabel.text.length > 0)?viewPix(8):0;
    [self.remarkLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(remarkTop);
    }];
    [self.tipLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.remarkLabel.mas_bottom).offset(stopTop);
    }];
}


#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.contentView addSubview:self.typeLabel];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.remarkLabel];
    [self.contentView addSubview:self.tipLabel];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.top.equalTo(self.contentView).offset(viewPix(4));
        make.bottom.equalTo(self.contentView).offset(viewPix(4));
    }];
    [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(28));
        make.top.equalTo(self.titleLabel);
        make.width.equalTo(@(viewPix(30)));
        make.height.equalTo(@(viewPix(18)));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(20));
        make.left.equalTo(self.typeLabel.mas_right).offset(viewPix(8));
        make.right.equalTo(self.contentView).offset(-viewPix(28));
    }];
    [self.remarkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(viewPix(8));
        make.left.right.equalTo(self.titleLabel);
    }];
    [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.remarkLabel.mas_bottom).offset(viewPix(8));
        make.left.right.equalTo(self.titleLabel);
        make.bottom.equalTo(self.contentView).offset(-viewPix(6));
    }];
}
-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UILabel *)typeLabel{
    if(!_typeLabel){
        _typeLabel = [UILabel lableWithText:@"" colorString:@"" textFont:LGFontWeight(10, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
        _typeLabel.cornerRidus = viewPix(9);
    }
    return _typeLabel;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _titleLabel;
}

-(UILabel *)remarkLabel{
    if(!_remarkLabel){
        _remarkLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(13) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _remarkLabel;
}

-(UILabel *)tipLabel{
    if(!_tipLabel){
        _tipLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(13) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _tipLabel;
}


@end
